package com.ssy.lingxi.platform.template.service.controller.adorn;

import com.ssy.lingxi.common.constant.basic.UserLoginSourceEnum;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.template.service.entity.adorn.Advert;
import com.ssy.lingxi.platform.template.service.model.bo.ColumnBO;
import com.ssy.lingxi.platform.template.service.model.dto.adorn.*;
import com.ssy.lingxi.platform.template.service.model.dto.common.TemplateIdDTO;
import com.ssy.lingxi.platform.template.service.model.dto.web.RecommendDTO;
import com.ssy.lingxi.platform.template.service.model.vo.adorn.*;
import com.ssy.lingxi.platform.template.service.service.adorn.WebEnterpriseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 模板装修 - WEB企业商城装修
 * @author fhj
 * @version 2.0.0
 * @date 2020/12/15
 */
@Api(tags = "模板装修 - WEB企业商城装修")
@RestController
@RequestMapping("/template/adorn/webEnterprise")
public class WebEnterpriseController extends BaseController {

    @Resource
    private WebEnterpriseService webEnterpriseService;
    @Resource
    private HttpServletRequest request;

    /**
     * 如果请求来源是WEB企业商城且非游客身份进入时需要按登录人身份来展示不同商品价格（价格策略）
     * */
    @ApiOperation(value = "平台品类的装修内容")
    @GetMapping("/categoryAdorn")
    public Wrapper<CategoryAdornVO> categoryAdorn(@Valid CategoryAdornDTO dto, HttpServletRequest request) {
        return webEnterpriseService.categoryAdorn(dto, isLogin() && getSysUser(request).getLoginSource().equals(UserLoginSourceEnum.BUSINESS_WEB.getCode()) ? getSysUser(request) : null);
    }

    @ApiOperation(value = "根据类型获取广告")
    @GetMapping("/findAdvertsByType")
    public Wrapper<List<Advert>> findAdvertsByType(@Valid AdvertDTO dto) {
        return webEnterpriseService.findAdvertsByType(dto);
    }

    @ApiOperation(value = "获取导航栏")
    @GetMapping("/findColumn")
    public Wrapper<List<ColumnBO>> findColumn(@Valid TemplateIdDTO dto) {
        return webEnterpriseService.findColumn(dto);
    }

    @ApiOperation(value = "获取商品列表")
    @GetMapping("/findGoodsList")
    public Wrapper<PageData<GoodsVO>> findGoodsList(@Valid RecommendDTO dto) {
        return webEnterpriseService.findGoodsList(dto);
    }

    @ApiOperation(value = "获取店铺列表")
    @GetMapping("/findShopList")
    public Wrapper<PageData<ShopVO>> findShopList(@Valid RecommendDTO dto) {
        return webEnterpriseService.findShopList(dto);
    }

    @ApiOperation(value = "获取品牌列表")
    @GetMapping("/findBrandList")
    public Wrapper<PageData<BrandVO>> findBrandList(@Valid RecommendDTO dto) {
        return webEnterpriseService.findBrandList(dto);
    }

    @ApiOperation(value = "获取品类列表")
    @GetMapping("/findCategoryList")
    public Wrapper<CategoryAdornVO> findCategoryList(@Valid RecommendDTO dto) {
        return webEnterpriseService.findCategoryList(dto, request);
    }

    @ApiOperation(value = "保存广告")
    @PostMapping("/saveAdvert")
    public Wrapper<Void> saveAdvert(@RequestBody @Valid SaveAdvertDTO dto) {
        return webEnterpriseService.saveAdvert(dto);
    }

    @ApiOperation(value = "保存导航栏")
    @PostMapping("/saveColumn")
    public Wrapper<Void> saveColumn(@RequestBody @Valid SaveColumnDTO dto) {
        return webEnterpriseService.saveColumn(dto);
    }

    @ApiOperation(value = "保存商品")
    @PostMapping("/saveGoods")
    public Wrapper<Void> saveGoods(@RequestBody @Valid SaveTemplateAdornDTO dto) {
        return webEnterpriseService.saveGoods(dto);
    }

    @ApiOperation(value = "保存店铺")
    @PostMapping("/saveShop")
    public Wrapper<Void> saveShop(@RequestBody @Valid SaveTemplateAdornDTO dto) {
        return webEnterpriseService.saveShop(dto);
    }

    @ApiOperation(value = "保存品牌")
    @PostMapping("/saveBrand")
    public Wrapper<Void> saveBrand(@RequestBody @Valid SaveTemplateAdornDTO dto) {
        return webEnterpriseService.saveBrand(dto);
    }

    @ApiOperation(value = "保存品类")
    @PostMapping("/saveCategory")
    public Wrapper<Void> saveCategory(@RequestBody @Valid SaveTemplateAdornDTO dto) {
        return webEnterpriseService.saveCategory(dto);
    }
}
